package org.vshe.improve.spring.prospring3.ch7.introductions;

import org.springframework.aop.IntroductionAdvisor;
import org.springframework.aop.framework.ProxyFactory;

public class IntroductionExample {
	public static void main(String args[]) {
		TargetBean target = new TargetBean();
		target.setName("Clarencde Ho");
		
		IntroductionAdvisor advisor = new IsModifiedAdvisor();
		
		ProxyFactory pf = new ProxyFactory();
		pf.setTarget(target);
		pf.addAdvisor(advisor);
		pf.setOptimize(true);
		
		TargetBean proxy = (TargetBean) pf.getProxy();
		
		System.out.println("Is TargetBean?: " + (proxy instanceof TargetBean));
		System.out.println("Is IsModified?: " + (proxy instanceof IsModified));
		
		System.out.println("Is modified?: " + ((IsModified) proxy).isModified());
		
		proxy.setName("Another name");
		
		System.out.println("Is modified?: " + ((IsModified) proxy).isModified());
		
	}
}
